﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WP7Client.Helpers;

namespace WP7Client.Controller
{
    public class WebBrowserController : BaseController
    {
        private String currentPageURL;
        private String lastCheckedURL;
        private Boolean isValidURL = false;

        public WebBrowserController() { }

        public String CurrentPageURL
        {
            get { return currentPageURL; }
            set 
            { 
                currentPageURL = value; 
                OnPropertyChanged("CurrentPageURL");
            }
        }

        public String LastCheckedURL
        {
            get { return lastCheckedURL; }
            set 
            {
                lastCheckedURL = value;
                OnPropertyChanged("LastCheckedURL");

                ControllerHelper.SocialNetworkAccountController.CheckIfIsFinished(value);
            }
        }

        public Boolean IsValidURL
        {
            get { return isValidURL; }
            set 
            { 
                isValidURL = value;
                if (value)
                {
                    ControllerHelper.SocialNetworkAccountController.Update();
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        /*if (ControllerHelper.OverviewController != null && ControllerHelper.OverviewController.OverviewPage != null)
                        {
                            ControllerHelper.MyProfileController = new ProfileController(ControllerHelper.OverviewController.OverviewPage.PivotItemMyProfile);
                        }*/

                        GlobalHelper.ShowMessage("Succes!", "Social network is succesfully added.");
                        NavigationHelper.NavigateTo("/UserInterface/Pages/OverviewPage.xaml?PivotItemName=PivotItemSocialNetworks");

                        ControllerHelper.MyProfileController.Update();
                    });                    
                }
                else
                {
                    GlobalHelper.ShowMessage("Error", "Authentication failed.");
                    NavigationHelper.NavigateTo("/UserInterface/Pages/OverviewPage.xaml?PivotItemName=PivotItemSocialNetworks");
                }
            }
        }

        public override void Update()
        {
            base.Update();
        }
    }
}
